Ext.namespace('pages.p2p.tx.querymx');

pages.p2p.tx.querymx.Main = function(config) {
	Ext.apply(this, config);
	this.initUIComponents();
	pages.p2p.tx.querymx.Main.superclass.constructor.call(this);
};

Ext.extend(pages.p2p.tx.querymx.Main, Ext.Panel, {
	/**
	 * 构造函数
	 */
	initUIComponents : function() {
		
		this.queryForm = new Ext.form.FormPanel({
			layout : 'column',
			region : 'north',
			labelWidth : 100,
			labelAlign : 'right',
			autoHeight :true,
			border : false,
			frame : false,
			items : [{
				columnWidth : 1,
				height : 4,
				border : false
			},{
                columnWidth : .25,
                layout : 'form',
                border : false,
                items : [{
                    fieldLabel : '处理开始日期',
                    name : 'OPER_START_DATE',
                    id : 'OPER_START_DATE',
                    anchor : '96%',
                    format : 'Y-m-d',
                    xtype : 'datefield'
                }]
            }, {
                columnWidth : .25,
                layout : 'form',
                border : false,
                items : [{
                    fieldLabel : '处理结束日期',
                    name : 'OPER_END_DATE',
                    id : 'OPER_END_DATE',
                    anchor : '96%',
                    format : 'Y-m-d',
                    xtype : 'datefield'
                }]
            }, {
				columnWidth : .25,
				layout : 'form',
				border : false,
				items : [{
					fieldLabel : '手机号',
					name : 'SJHM',
					id : 'SJHM',
					anchor : '96%',
					xtype : 'textfield'
				}]
			}, {
				columnWidth : .25,
				layout : 'form',
				border : false,
				items : [{
					fieldLabel : '用户名',
					name : 'GYH',
					id : 'GYH',
					anchor : '96%',
					xtype : 'textfield'
				}]
			},{
				columnWidth : .25,
				layout : 'form',
				border : false,
				hidden : false,
				items : [ new Ext.form.ComboBox({
					fieldLabel : '提现状态',
					name : 'TX_STATE',
					id : 'TX_STATE',
					anchor : '96%',
					store : new Ext.data.SimpleStore({
						fields : [ 'VALUE', 'TEXT' ],
						data : [ [ '00', '待处理' ],[ '01', '提现成功' ],
								[ '02', '提现失败' ],[ '', '全部' ]]
					}),
					valueField : 'VALUE',
					displayField : 'TEXT',
					hiddenName : 'TX_STATE_VALUE',
					triggerAction : 'all',
					mode : 'local',
					editable : false,
					selectOnFocus : true,
					value : '01'
				}) ]
			}]
		});
		this.store = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				url : ExtJ.getActionPath('tx/queryTxList.do')
			}),
			remoteSort : true,
			reader : new Ext.data.JsonReader({
				root : 'data',
				totalProperty : 'total',
				SumJe:'SumJe',
				id : 'ID'
			}, [{
				name : 'ID',
				mapping : 'ID'
			},{
				name : 'GYH',
				mapping : 'GYH'
			},{
				name : 'TXSJ',
				mapping : 'TXSJ'
			},{
				name : 'TX_STATE',
				mapping : 'TX_STATE'
			},{
				name : 'SXF',
				mapping : 'SXF'
			},{
				name : 'TXJE',
				mapping : 'TXJE'
			},{
				name : 'CardName',
				mapping : 'CardName'
			},{
				name : 'KYJE',
				mapping : 'KYJE'
			},{
				name : 'ZHYE',
				mapping : 'ZHYE'
			},{
				name : 'SJHM',
				mapping : 'SJHM'
			},{
				name : 'YHKHM',
				mapping : 'YHKHM'
			},{
				name : 'KHH',
				mapping : 'KHH'
			},{
				name : 'KHHSZD',
				mapping : 'KHHSZD'
			},{
				name : 'YHMC',
				mapping : 'YHMC'
			},{
				name : 'SFZHM',
				mapping : 'SFZHM'
			},{
				name : 'OPER_GYH',
				mapping : 'OPER_GYH'
			},{
				name : 'OPER_DATE',
				mapping : 'OPER_DATE'
			}
			
			])
		});
		
		
		this.eug_gs = new Ext.ux.grid.GridSummary();
		var sm = new Ext.grid.CheckboxSelectionModel({
			singleSelect : false,
			listeners : {/*
				'rowselect' : function(sm,rowIndex,record){
					var sh_state = record.get("TX_STATE");
					if('00' == sh_state ){
						Ext.getCmp('tx_suc_btn').setDisabled(false);
						Ext.getCmp('tx_fail_btn').setDisabled(false);
					}else{
						Ext.getCmp('tx_suc_btn').setDisabled(true);
						Ext.getCmp('tx_fail_btn').setDisabled(true);
					}
				}
			*/}
		});
		var cm = new Ext.grid.ColumnModel([sm,new Ext.grid.RowNumberer(),{
				header : '用户名',
				width : 120,
				sortable : true,
				dataIndex : 'GYH',
				summaryRenderer : function(val){  
				       return '<span style="color:#000000;font-weight:bold;font-size:18px;">' +  '提现合计 :</span>';  
				   }.createDelegate(this)
			},{
				header : '提现金额',
				width : 150,
				sortable : true,
				dataIndex : 'TXJE',
				summaryRenderer : function(val){  
					if(null == this.store.reader.jsonData || undefined == this.store.reader.jsonData){
						return "";
					}
				   var SumJe = this.store.reader.jsonData.SumJe;
			       return '<span style="color:#FF0000;font-weight:bold;font-size:18px;">'  + SumJe + '￥</span>';  
			   }.createDelegate(this)
			},{
				header : '提现时间',
				width : 160,
				sortable : true,
				dataIndex : 'TXSJ'
			},{
				header : '银行卡号',
				width : 200,
				sortable : true,
				dataIndex : 'YHKHM'
			},{
				header : '提现状态',
				width : 100,
				sortable : true,
				dataIndex : 'TX_STATE',
				renderer : function(value){
					if("00" == value){
						return "待处理";
					}else if("01" == value){
						return "提现成功";
					}else if("02" == value){
						return "提现失败";
					}else{
						return value;
					}
				}
			},{
				header : '手机号码',
				width : 100,
				sortable : true,
				dataIndex : 'SJHM'
			},{
				header : '姓名',
				width : 50,
				sortable : true,
				dataIndex : 'CardName'
			},{
				header : '可用金额',
				width : 100,
				sortable : true,
				dataIndex : 'KYJE'
			},{
				header : '账户余额',
				width : 100,
				sortable : true,
				dataIndex : 'ZHYE'
			},{
				header : '身份证号',
				width : 150,
				sortable : true,
				dataIndex : 'SFZHM'
			},{
				header : '开户行',
				width : 200,
				sortable : true,
				dataIndex : 'KHH'
			},{
				header : '开户行所在地',
				width : 100,
				sortable : true,
				dataIndex : 'KHHSZD'
			},{
				header : '银行名称',
				width : 100,
				sortable : true,
				dataIndex : 'YHMC'
			},{
				header : '处理人',
				width : 100,
				sortable : true,
				dataIndex : 'OPER_GYH'
			},{
				header : '处理日期',
				width : 160,
				sortable : true,
				dataIndex : 'OPER_DATE'
			}
			]);
			
		
		/**
		 * GridPanel
		 */
		this.grid = new Ext.grid.GridPanel({
			id : 'grid',
			region : 'center',
			store : this.store,
			plugins : this.eug_gs,
			border : true,
			frame : false,
			viewConfig : {
				autoFill : false,
	    	    forceFit : false,
	    	    focusRow : function(){
	    	    	return;
	    	    },
	    	    getRowClass : function(record, rowIndex, rowParams, store){
	    	    	if ("00" == record.get("TX_STATE")) {
				        return 'ux-grid-record-onTop';
				    }
	    	    }
			},
			sm : sm,
			cm : cm,
			tbar : [{				
				id : 'query',
				iconCls : 'query',
				text : '查询',
				handler : this.onQuery.createDelegate(this)
			},'-', {
				id : 'reset',
				iconCls : 'reset',
				text : '重置',
				handler : this.onReset.createDelegate(this)
			}, '-', {
				id : 'view',
				iconCls : 'view',
				text : '查看',
				handler : this.onView.createDelegate(this)
			},'-', {
				id : 'export',
				iconCls : 'excel',
				text : '导出excel',
				handler : this.onExport.createDelegate(this)
			}, '-', {
				id : 'view_tz',
				iconCls : 'view',
				text : '用户投资记录',
				handler : this.onTzxx.createDelegate(this)
			}],
			bbar : new Ext.PagingToolbar({
				pageSize : pageSize,
				store : this.store,
				displayInfo : true,
				displayMsg : '当前显示第 {0} - {1} 条 / 共 {2} 条',
				emptyMsg : "没有记录"
			})
		});
		
		Ext.apply(this, {
			title : '提现查询',
			closeAction : 'close',
			layout : 'border',
			border : false,
			tools : [{
						id : 'help',
						handler : function(){
							this.onHelp();				
						}.createDelegate(this)
					}],
			listeners : {
				'render' : this.initData.createDelegate(this)
			},
			items : [this.queryForm,this.grid]
		})
	},

	initData : function(){
		var todayDate = new Date();
		var yesterdayDate = new Date();
		yesterdayDate.setDate(yesterdayDate.getDate() -1 );
		Ext.getCmp('OPER_START_DATE').setValue(yesterdayDate);
		Ext.getCmp('OPER_END_DATE').setValue(yesterdayDate);
		this.onQuery();
	},
	
	onHelp : function(){
		var dialog = new global.help.HelpWindow({key : 'cw.all.helpTxcx'});
		dialog.show();
	},
	
	
	onQuery : function(){
		this.store.baseParams.startDate = "";
		this.store.baseParams.endDate = "";
		this.store.baseParams.sjhm = Ext.getCmp('SJHM').getValue();
		this.store.baseParams.gyh = Ext.getCmp('GYH').getValue();
		this.store.baseParams.txState = Ext.getCmp('TX_STATE').getValue();
		/*var startDate=this.store.baseParams.startDate;
		var endDate=this.store.baseParams.endDate ;
		if(startDate>endDate){
			Ext.Msg.alert('提示', '提现开始日期不能大于提现结束日期!');
			return;
		}*/
		/**
		 * 新增处理日期查询
		 * 2017-02-10
		 * xuef
		 * */
		this.store.baseParams.operStartDate = Ext.getCmp('OPER_START_DATE').getRawValue();
		this.store.baseParams.operEndDate = Ext.getCmp('OPER_END_DATE').getRawValue();
		var operStartDate=this.store.baseParams.operStartDate;
		var operEndDate=this.store.baseParams.operEndDate ; 
		if(operStartDate > operEndDate){
			Ext.Msg.alert('提示', '处理开始日期不能大于处理结束日期!');
			return;
		}
		
		Ext.getBody().mask("正在查询,请稍候...");
		var count = this.store.getCount();
        if(count>0){
            this.grid.getStore().removeAll();
            this.store.reader.jsonData.sumJe=0;
            this.eug_gs.refreshSummary();
        }
		this.store.reload({
			params : {
				start : 0,
				limit : pageSize
			},
			callback : function() {
				Ext.getBody().unmask(true);
			}.createDelegate(this)
		});
	},
	onReset : function(){
		this.queryForm.getForm().reset();
	},
	onView : function() {
		var records = this.grid.getSelectionModel().getSelections();
		if (records.length < 1) {
			ExtJ.showMessage("请选择一条需要查看的记录!");
			return;
		}else if (records.length > 1) {
			ExtJ.showMessage("只能选择一条记录查看!");
			return;
		}
		var record = records[0];
		var win = new pages.p2p.tx.querymx.View({
			operType : 'view',
			record : record
		});
		win.show();
	},
	
	onExport : function(){
		this.store.baseParams.startDate = "";
		this.store.baseParams.endDate = "";
		this.store.baseParams.sjhm = Ext.getCmp('SJHM').getValue();
		this.store.baseParams.gyh = Ext.getCmp('GYH').getValue();
		this.store.baseParams.txState = Ext.getCmp('TX_STATE').getValue();
		var startDate = this.store.baseParams.startDate;
		var endDate = this.store.baseParams.endDate;
		var sjhm = this.store.baseParams.sjhm;
		var gyh = this.store.baseParams.gyh;
		var txState = this.store.baseParams.txState;
		var operStartDate = Ext.getCmp('OPER_START_DATE').getRawValue();
		var operEndDate = Ext.getCmp('OPER_END_DATE').getRawValue();
		var url  = 	baseUrl + "/tx/exportTxExcelMethod.do?startDate="+startDate+"&endDate="+endDate+"&sjhm="+sjhm+"&gyh="+gyh+"&txState="+txState+"&operStartDate="+operStartDate+"&operEndDate="+operEndDate;	
		ExtJ.doExport({url:url});
	},
	onTzxx : function() {
		var records = this.grid.getSelectionModel().getSelections();
		if (records.length < 1) {
			ExtJ.showMessage("请选择一条需要查看的记录!");
			return;
		}else if (records.length > 1) {
			ExtJ.showMessage("只能选择一条记录查看!");
			return;
		}
		var record = records[0];
		var win = new pages.p2p.tx.querymx.ViewTzxx({
			operType : 'viewtz',
			record : record
		});
		win.show();
	}
});